﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.Modeling.CUiSetEndModelingSimulationViewModel
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Windows;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands.Modeling;

public class CUiSetEndModelingSimulationViewModel : ObservableObject
{
  private bool _doNotShowAgain;

  public bool DoNotShowAgain
  {
    get => this._doNotShowAgain;
    set => this.Set<bool>(ref this._doNotShowAgain, value, nameof (DoNotShowAgain));
  }

  public CUiSetEndModelingSimulationGeneralCommand ContinueAnywayCommand { get; set; }

  public CUiSetEndModelingSimulationGeneralCommand CancelCommand { get; set; }

  public CUiSetEndModelingSimulationViewModel()
  {
    this.ContinueAnywayCommand = new CUiSetEndModelingSimulationGeneralCommand(new Action<TxWindow>(this.ProceedAction));
    this.CancelCommand = new CUiSetEndModelingSimulationGeneralCommand(new Action<TxWindow>(this.TerminateAction), new Func<bool>(this.CanTerminateAction));
  }

  private bool CanTerminateAction() => !this.DoNotShowAgain;

  private void TerminateAction(TxWindow window)
  {
    this.HandleSelection(false, window);
    this.CloseWindow(window);
  }

  private void ProceedAction(TxWindow window)
  {
    this.HandleSelection(true, window);
    this.CloseWindow(window);
  }

  private void CloseWindow(TxWindow window) => ((Window) window)?.Close();

  private void HandleSelection(bool proceed, TxWindow wnd)
  {
    CApSetEndModelingApp.ShouldContinue = proceed;
    if (!proceed || !this.DoNotShowAgain)
      return;
    this.Persist(wnd);
  }

  private void Persist(TxWindow wnd) => CApSetEndModelingApp.SaveValueToRegistry(wnd, "1");
}
